package com.ccx.coachsite.ui.login;

import com.ccx.coachsite.R;
import com.ccx.coachsite.http.UrlConfig;

import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class ThirdRegisterActivity extends Activity {

	private String thirdToken;
	private WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.register_third_view);

		ImageButton btnReturn = (ImageButton) findViewById(R.id.login_btn_return);
		btnReturn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ThirdRegisterActivity.this.finish();
			}
		});

		TextView txtTitle = (TextView) findViewById(R.id.login_top_title);
		txtTitle.setText("注册");
		webView = (WebView) findViewById(R.id.register_webview);
		webView.setWebViewClient(new WebViewClient() {

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				// TODO Auto-generated method stub
				super.onPageStarted(view, url, favicon);
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				// TODO Auto-generated method stub
				super.onPageFinished(view, url);
			}

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				Toast.makeText(ThirdRegisterActivity.this, url,
						Toast.LENGTH_SHORT).show();
				return super.shouldOverrideUrlLoading(view, url);
			}

			@Override
			public void onReceivedSslError(WebView view,
					SslErrorHandler handler, SslError error) {
				handler.proceed();
			}
		});

		thirdToken = getIntent().getStringExtra("ThirdToken");
		if ("sina".equals(thirdToken)) {
			String url = UrlConfig.getUrlByKey(UrlConfig.RegisterSina);
			webView.loadUrl(url);
		} else if ("qq".equals(thirdToken)) {
			String url = UrlConfig.getUrlByKey(UrlConfig.RegisterQQ);
			webView.loadUrl(url);
		}
	}

}
